// pages/my/myPoints/myPoints.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showUrl:'',
    req: false,
    list: [],
    params: {
      customerId: null,
      pageNo: 1,
      pageSize: 20
    }
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  toDetail(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/order/orderDetail/orderDetail?id=' + id,
    })
  },
  list(append) {
    let that = this;
    that.toggle("req", false);
    app.req({
      url: "/order/busOrder/list",
      data: that.data.params,
      complete() {
        that.toggle("req", true);
      },
      success(res) {
        if (200 == res.code) {
          let list = that.data.list;
          that.toggle("list", append ? list.concat(res.result.records) : res.result.records);
          that.toggle("params.totalPages", res.result.pages)
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.toggle("showUrl", app.globalData.showUrl);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  refreshData() {
    let that = this;
    app.getUserInfo({
      success(res) {
        that.toggle("params.customerId", res.id);
        that.toggle("params.pageNo", 1);
        that.list();
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.refreshData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.refreshData();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let params = this.data.params;
    if (params.totalPages > params.pageNo) {
      this.toggle("params.pageNo", params.pageNo + 1);
      this.list(true);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})